CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )

SET( PROJECT_NAME_TEMP "PhiolLib" )

# Determine the Phidget21 API include and library paths. 
# Once done, the following is defined
#  PHIDGET21_FOUND - system has Phidget21
#  Phidget21_INCLUDE_DIR - the Phidget21 include directories
#  Phidget21_LIBRARY - link these to use Phidget21
IF( CMAKE_SYSTEM_NAME MATCHES "Windows" )

	# On Windows, the standard install path of for Phidget is the following Determine the Phidget21 include directory by finding a particular header
	SET( Phidget21_DEFAULT_INSTALL_PATH "C:/Program Files/Phidgets" )
	
	# Try to determine the include path (by looking for the main header)
	FIND_PATH( Phidget21_INCLUDE_DIR NAMES phidget21.h PATHS ${Phidget21_DEFAULT_INSTALL_PATH} )

	# Depending on the architecture (x86 or x64), try to determine the library path
	IF ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
		FIND_LIBRARY( Phidget21_LIBRARY NAMES phidget21 PATHS ${Phidget21_DEFAULT_INSTALL_PATH} )
	ELSE()
		FIND_LIBRARY( Phidget21_LIBRARY NAMES phidget21 PATHS "${Phidget21_DEFAULT_INSTALL_PATH}/x86" )
	ENDIF()
	
ELSEIF( CMAKE_SYSTEM_NAME MATCHES "Darwin" )

	# On MacOS, if the Phidget21 framework has been properly installed, CMake should find it automatically
	FIND_PATH( Phidget21_INCLUDE_DIR NAMES phidget21.h )
	FIND_LIBRARY( Phidget21_LIBRARY NAMES Phidget21 )
	
ELSEIF( CMAKE_SYSTEM_NAME MATCHES "Linux" )

	FIND_PATH( Phidget21_INCLUDE_DIR NAMES phidget21.h  )
	FIND_LIBRARY( Phidget21_LIBRARY NAMES phidget21 )

ENDIF()

# Handle the QUIETLY and REQUIRED arguments and set PHIDGET21_FOUND to TRUE if all listed variables are TRUE
# Note that this necessarily generates a upper-case variable name! 
INCLUDE( FindPackageHandleStandardArgs )
FIND_PACKAGE_HANDLE_STANDARD_ARGS( Phidget21 DEFAULT_MSG Phidget21_LIBRARY Phidget21_INCLUDE_DIR )

#
# Phiol settings
# 
IF( PHIDGET21_FOUND )

	MESSAGE( "Found Phidget21" )
	MESSAGE( "Phidget21_INCLUDE_DIR:	${Phidget21_INCLUDE_DIR}" )
	MESSAGE( "Phidget21_LIBRARY: 	${Phidget21_LIBRARY}" )

	PROJECT( ${PROJECT_NAME_TEMP} )

	SET	(	SOURCES
			PhiolVector3.h
			PhiolDevice.h
			PhiolDevice.cpp
			PhiolSpatial.h
			PhiolSpatial.cpp
			PhiolTemperatureSensor.h
			PhiolTemperatureSensor.cpp
			PhiolDeviceManager.h
			PhiolDeviceManager.cpp
			PhiolLocalDeviceManager.h
			PhiolLocalDeviceManager.cpp
			PhiolRemoteDeviceManager.h
			PhiolRemoteDeviceManager.cpp
		)	
		
	IF( CMAKE_SYSTEM_NAME MATCHES "Windows" )
		ADD_DEFINITIONS(-DUNICODE -D_UNICODE)		# Set Unicode as character set for Visual Studio projects. By default it's Multi-Byte
	ENDIF()

	INCLUDE_DIRECTORIES( ${Phidget21_INCLUDE_DIR} ) 
	
	ADD_LIBRARY( ${PROJECT_NAME} STATIC ${SOURCES} )

	TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${Phidget21_LIBRARY} )

ELSE()
	
	MESSAGE("Can't find Phidget 21 library. Project ${PROJECT_NAME_TEMP} won't be compiled")

ENDIF()





